package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.Role;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface RoleMapper extends BaseMapper<Role> {
    @Select("select tr.id,tr.keyword from t_user_role tur,t_role tr where tur.role_id = tr.id and tur.user_id = #{userId}")
    List<Role> findRolesByUserId(Integer userId);
    @Insert("insert into t_role_menu values(#{groupId},#{itemId})")
    public void addCheckgroupWithCHeckitem(@Param("groupId")int groupId, @Param("itemId") int itemId);

    @Select("select menu_id from t_role_menu where role_id = #{groupId}")
    public List<Integer> findCheckitemIds(Integer groupId);

    @Delete("delete from t_role_menu where role_id = #{groupId}")
    public void deleteCheckitemsByGroupId(Integer groupId);

    @Select("select tc.name from t_role_menu trm,t_menu tm" +
            " where trm.menu_id = tm.id" +
            " and trm.role_id = #{id}" +
            " and trm.is_delete = 0")
    public List<CheckItem> findCheckItemByCheckgroupId(Integer id);
}
